package com.bjpowernode.springboot.web;

import com.bjpowernode.springboot.model.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @DATE 2021--11--28 21:59
 */
//@Controller
@RestController  //相当于控制层类上加@Controller + 方法上加@ResponseBody,意味着当前控制层类中所有方法返还的都是JSON对象
public class StudentController {

    @RequestMapping(value = "/student")
//    @ResponseBody
    public Object student(){
        Student student = new Student();
        student.setId(1001);
        student.setName("zhangsan");
        return student;
    }

    //该方法请求方式支持get和post方式请求
    @RequestMapping(value = "/studentDetail")
    public Object queryStudentById(Integer id){
        Student student = new Student();
        student.setId(id);
        return student;
    }

//    @RequestMapping(value = "/queryStudentById2",method = RequestMethod.GET)
    @GetMapping(value = "/queryStudentById2")  //相当于上面句话，只接受GET请求，如果请求方式不对会405错误
   //查询数据的时候使用
    public Object queryStudentById2(){
        return "Ony GET Method";
    }

//    @RequestMapping(value = "/Insert",method = RequestMethod.POST)
    @PostMapping(value = "/Insert")//相当于上面的那句话
    public Object Insert(){
        return "Insert success";
    }

//    @RequestMapping(value = "/delete",method = RequestMethod.DELETE)
    @DeleteMapping(value = "/delete")//相当于上面那句话
    //该注解通常删除数据的时候使用
    public Object delete(){
        return "Delete Student";
    }

//    @RequestMapping(value = "/update",method = RequestMethod.PUT)
    @PutMapping(value = "update")
    public Object update(){
        return "Update Student info";
    }
}
